#include "EnterScene.h"
#include "Player.h"
#include "Archives.h"


Scene* Enter_Scene::createScene()
{
	// 'scene' is an autorelease object
	auto scene = Scene::create();

	// 'layer' is an autorelease object
	auto layer = Enter_Scene::create();
	// add layer as a child to scene
	scene->addChild(layer);

	// return the scene
	return scene;
}


Enter_Scene::Enter_Scene()
{
	_Enter_Scene_Layer = NULL;
}

Enter_Scene::~Enter_Scene()
{

}

bool Enter_Scene::init()
{
	bool bRef = false;
	do
	{
		CC_BREAK_IF(!CCScene::init());
		LoadPicResourceToCaChe();
		LoadPlayerProperty();

		_Enter_Scene_Layer = Enter_Scene_Layer::create();
		CC_BREAK_IF(!_Enter_Scene_Layer);
		addChild(_Enter_Scene_Layer);

		bRef = true;


	} while (0);

	return bRef;
}
void Enter_Scene::LoadPlayerProperty()
{
	if (Archives::sharedArchives()->IsExistAndCanUseArchives())
	{
		Archives::sharedArchives()->GetPlayer_Property(*Player::SharedPlayer());
		Player::SharedPlayer()->ConnectServer();
		Player::SharedPlayer()->SuccessToConnectServer();
	}
	else
	{
		Player::SharedPlayer()->setPlayerName("test");
		Player::SharedPlayer()->setPlayerLevel(1);
		Player::SharedPlayer()->setPlayerExp(100);
		Player::SharedPlayer()->setPlayerMoney(0);
		Player::SharedPlayer()->setPlayerLeaderShip(100);
		Player::SharedPlayer()->setPlayerDiamond(0);
		Player::SharedPlayer()->setPlayerTeamLevel(0);
		Player::SharedPlayer()->setPlayerPvpRank(0);
		Player::SharedPlayer()->setPlayerStrength(100);
		Player::SharedPlayer()->ConnectServer();
		Player::SharedPlayer()->SuccessToConnectServer();
		CCUserDefault::sharedUserDefault()->setBoolForKey("IsHaveSaveFileXml", true);
		Archives::sharedArchives()->SetPlayer_Property(*Player::SharedPlayer());
	}
}

void Enter_Scene::LoadPicResourceToCaChe()
{
	CCSpriteFrameCache * _CCSpriteFrameCache = CCSpriteFrameCache::sharedSpriteFrameCache();

	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/bigcard_0000_0004.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/bigcard_0329_0335.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/bigcard_0337_0343.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/bigcard_0345_0351.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/bigcard_0489_0494.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/bigcard_frame_greenandblue.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/bigcard_frame_purpleandyellow.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/bigcard_frame_white.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/eatcard_part1.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/equipment_part1.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/equipment_part2.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/evolution.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/fight_star.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/fight_victroy.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/heal.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/login_animation.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/play_image.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/play_script1.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/play_script2.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/raffle.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/skill_customattack.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/skill_tenarmy.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/skill_thunde.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/skill_windhit.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/skill_zhongji.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/skille_blizzard.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_arena.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_eatcard.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_fight.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_friend.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_icon.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_list_button.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_listbutton1.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_littcard_frame.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_littlebutton.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_mainface.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_navigation.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_occupation.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_rank.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_serverlist.plist");
	_CCSpriteFrameCache->addSpriteFramesWithFile("ui/ui_text.plist");
}